package org.micro.frame.mybatis.plus.configuration;

import org.beetl.sql.ext.spring4.BeetlSqlScannerConfigurer;
import org.beetl.sql.ext.spring4.SqlManagerFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * The Test1 Beetlsql Configuration
 *
 * @author lry
 */
@Configuration
public class Test1BeetlsqlConfig extends BaseConfiguration {

    @Primary
    @Bean("test1DataSource")
    @ConfigurationProperties("beetlsql.datasource.test1")
    public DataSource dataSource() {
        return super.buildDataSource();
    }

    @Primary
    @Bean("test1SqlManagerFactoryBean")
    public SqlManagerFactoryBean sqlManagerFactoryBean(@Qualifier("test1DataSource") DataSource dataSource) {
        BeetlsqlProperties beetlsqlProperties = new BeetlsqlProperties();
        beetlsqlProperties.setSqlRoot("/sql");
        beetlsqlProperties.setDebugInterceptor(true);
        return super.buildSqlManagerFactoryBean(dataSource, beetlsqlProperties);
    }

    @Primary
    @Bean("test1BeetlSqlScannerConfigurer")
    public BeetlSqlScannerConfigurer beetlSqlScannerConfigurer() {
        BeetlsqlProperties beetlsqlProperties = new BeetlsqlProperties();
        beetlsqlProperties.setBasePackage("org.micro.frame.mybatis.mapper.test1");
        beetlsqlProperties.setDaoSuffix("Mapper");
        return super.buildBeetlSqlScannerConfigurer("test1SqlManagerFactoryBean", beetlsqlProperties);
    }

}
